<%@page import="connection.ConnectionWrapper"%>
<%@page import="model.News"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*,java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- includes -->
<%@ include file="includes/includes.jsp"%>
<!-- fin includes -->

<title>JSPBlog</title>
</head>
<body>
<!-- cabecera -->
<%@ include file="includes/header.jsp"%>
<!-- fin cabecera -->

<div id="main">
	<div class="article">
	<table height="136" border="0" cellpadding="0"	cellspacing="0">
		<tbody>
			<tr>
				<td class="menu" valign="top"><a href="#TOP"></a>
				<!-- contenido central -->
				<%
					//   Connection c = null;
					Integer idNew = 0;
					String body = "";
					String title = "";
					String tittle = "";
					String author = "";
					String date = "";
	
					String busqueda = (String) request.getParameter("q");
	
					//  Class.forName("org.postgresql.Driver");
					News noticias = new News();
					List<News> lista = noticias.getNews(busqueda);
	
					Iterator iter = lista.iterator();
					Integer cont = 0;
					while (iter.hasNext()) {
						cont++;
						System.out.println(iter.next() + "cont : " + cont.toString());
					}
	
					for (News n : lista) {
						idNew = n.getIdNew();
						tittle = n.getTittle();
						date = n.getDate();
						author = n.getAuthor();
						body = n.getBody();
				%>
				<div class="article">
						<table border='0' cellpadding="0" align="center" class="blog">
							<tr>
								<td>
									<b><input type="hidden" value="<%=idNew %>"> <%= tittle %></b>
								</td>
							</tr>
							<tr>
								<td><%=body%></td>
							</tr>
							<tr>
								<td><%=date%></td>
							</tr>
							<tr>
								<td><i><%=author%></i></td>
							</tr>
							<%
								//String sesion = session.getAttribute("admin");
								String isAdmin="";
								if(session.getAttribute("admin")!=null){
									isAdmin = session.getAttribute("admin").toString();
								}
								
								if(isAdmin == "yes"){
							%>
								<tr>
									<td>
										<a href="admin/editnews.jsp?q=<%=idNew %>">Edit</a>
									</td>
								</tr>
							<%
								}
							%>
						</table>
				</div>
				<br />
				<hr>
				<%
					}
				%> <!-- fin contenido central --></td>
			</tr>
		</tbody>
	</table>
	</div>
</div>

<!-- menu  -->
<%@ include file="includes/menu.jsp"%>
<!--  fin menu  -->

<!-- footer  -->

<%@ include file="includes/footer.jsp"%>
<!--  fin footer -->
</body>
</html>